/*
 * File:   NodeComparatorByDistance.java
 * Author: Oleg S. Estekhin
 */
package dht.emulator;

import java.io.Serializable;
import java.util.Comparator;

final class NodeComparatorByDistance implements Comparator<Node>, Serializable
{

    private final Identifier identifier;

    public NodeComparatorByDistance(Identifier identifier)
    {
        this.identifier = identifier;
    }

    @Override
    public int compare(Node o1, Node o2)
    {
        Identifier d1 = identifier.getDistance(o1.getIdentifier());
        Identifier d2 = identifier.getDistance(o2.getIdentifier());
        return d1.compareTo(d2);
    }

}
